package com.qf.shopcar;

import java.sql.SQLOutput;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class tets {
    public static void main(String[] args) {
        Goods goods1 = new Goods("苹果", 12.0, 202);
        Goods goods2 = new Goods("香蕉", 10.0, 500);
        Goods goods3 = new Goods("地瓜", 4.0, 10000);
        Goods goods4 = new Goods("西红柿", 7.0, 1314);
        Goods goods5 = new Goods("葡萄", 20.0, 235);
        Goods goods6 = new Goods("西瓜", 5.0, 2342);
        Goods goods7 = new Goods("榴莲", 50.0, 158);

        List<Goods> list = new ArrayList<>();
        list.add(goods1);
        list.add(goods2);
        list.add(goods3);
        list.add(goods4);
        list.add(goods5);
        list.add(goods6);
        list.add(goods7);

        List<Goods> goodsList = list.stream().sorted(Comparator.comparing(Goods::getCount).reversed()).collect(Collectors.toList());

        goodsList = goodsList.stream()
                .skip(0)
                .limit(3)
                .collect(Collectors.toList());

        goodsList.forEach(System.out::println);
    }
}
